Skip to content

Fix AttributeError when Eleven Labs API key is not set#1238

Open
majiayu000 wants to merge 1 commit intokhoj-ai:masterfrom
majiayu000:fix/text-to-speech-no-api-key
Open

Fix AttributeError when Eleven Labs API key is not set#1238
majiayu000 wants to merge 1 commit intokhoj-ai:masterfrom
majiayu000:fix/text-to-speech-no-api-key

Conversation

@majiayu000
Copy link

Summary

  • Fixes AttributeError: 'str' object has no attribute 'iter_content' in text_to_speech endpoint
  • When ELEVEN_LABS_API_KEY is not configured, the function was returning a string instead of a Response object

Changes

  • Introduced TextToSpeechError exception class in text_to_speech.py
  • Changed generate_text_to_speech to raise exception instead of returning error string
  • Updated API endpoint to catch the exception and return HTTP 501 (Not Implemented)

Test plan

  • Code passes ruff lint check
  • Manual testing with and without Eleven Labs API key configured

Fixes #1049

When ELEVEN_LABS_API_KEY is not configured, generate_text_to_speech
was returning a string instead of a Response object, causing
AttributeError: 'str' object has no attribute 'iter_content'.

This fix:
- Introduces TextToSpeechError exception class
- Raises exception instead of returning error string
- API endpoint catches the exception and returns HTTP 501

Fixes khoj-ai#1049

Signed-off-by: majiayu000 <1835304752@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] AttributeError: 'str' object has no attribute 'iter_content'

1 participant